package cheme.Application;

import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.internal.provisional.action.CoolBarManager2;
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
import org.eclipse.jface.internal.provisional.action.ToolBarContributionItem2;
import org.eclipse.jface.internal.provisional.action.ToolBarManager2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
import org.eclipse.ui.presentations.IStackPresentationSite;
import org.eclipse.ui.presentations.StackPresentation;
import org.eclipse.ui.presentations.WorkbenchPresentationFactory;

/*
 * This class, facilitates excluding unwaantedcontributions from the UI. IT relies on EXPERIMENTAL
 * eclipse platform features that may not persis in future versions.
 *  @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory
 * TODO: Verify that this becomes non-experimental in future releases of Eclipse.
 */

public class PresentationFactory extends WorkbenchPresentationFactory implements IActionBarPresentationFactory
{
	public static final String ID = "cheme.Application.PresentationFactory";
	
	public PresentationFactory()
	{
	}

	@Override
	public StackPresentation createEditorPresentation(Composite parent, IStackPresentationSite site)
	{
		return super.createEditorPresentation(parent, site);
	}

	@Override
	public StackPresentation createStandaloneViewPresentation(Composite parent, IStackPresentationSite site, boolean showTitle)
	{
		return super.createStandaloneViewPresentation(parent, site, showTitle);
	}

	@Override
	public StackPresentation createViewPresentation(Composite parent, IStackPresentationSite site)
	{
		return super.createViewPresentation(parent, site);
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createCoolBarManager()
	 */
	public ICoolBarManager2 createCoolBarManager()
	{
		return new CoolBarManager2(SWT.FLAT)
		{
			/*
			 * TODO: This could be made to reference a list of dissallowed IDs so that future use of plugins does not force unwanted GUI elements as well.
			 * 
			 * (non-Javadoc)
			 * @see org.eclipse.jface.action.CoolBarManager#allowItem(org.eclipse.jface.action.IContributionItem)
			 */
			@Override
			protected boolean allowItem(IContributionItem itemToAdd)
			{				
				if(null != itemToAdd && itemToAdd.getId().equals("org.eclipse.ui.WorkingSetActionSet"))
				{
					return false;
				}
				
				return super.allowItem(itemToAdd);
			}
		};
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createToolBarManager()
	 */
	public IToolBarManager2 createToolBarManager()
	{
		return new ToolBarManager2(SWT.FLAT | SWT.RIGHT);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createViewToolBarManager()
	 */
	public IToolBarManager2 createViewToolBarManager()
	{
		return new ToolBarManager2(SWT.FLAT | SWT.RIGHT | SWT.WRAP);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createToolBarContributionItem(org.eclipse.jface.action.IToolBarManager, java.lang.String)
	 */
	public IToolBarContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id)
	{
		return new ToolBarContributionItem2(toolBarManager, id);
	}

}
